<!DOCTYPE html>
<html lang="en">
<head>
    <title>编辑</title>
    <link rel="stylesheet" href="${ctxPath!}/js/extend/formSelect/formSelects-v4.css"/>
    <%include("/WEB-INF/views/common/basejs.html"){}%>
    <script>
        //全局定义一次, 加载formSelects
        var pid='${baseData.pid!}';
        layui.config({
            base: '../js/extend/formSelect/' //此处路径请自行处理, 可以使用绝对路径
        }).extend({
            formSelects:'formSelects-v4'
        }).use(['formSelects','form'],function(){
            var form = layui.form,
                formSelects=layui.formSelects,
                $=layui.jquery;
            var baseDataListStr='${baseDataListStr!}';
            var baseDataList;
            if(baseDataListStr){
                baseDataList=JSON.parse(baseDataListStr);
            }
            //初始化组织结构下拉树
            formSelects.data('pid','server',{
                url:basePath+'/baseData/showBaseDataTree',
                success:function(){
                    //禁用本身菜单
                    if(baseDataList&&baseDataList.length){
                        for(i in baseDataList){
                            $('dd[lay-value="'+baseDataList[i].id+'"]').addClass("xm-dis-disabled");
                        }
                    }
                    //设置默认值
                    if(pid){
                        formSelects.value('pid', [${baseData.pid!}]);
                    }
                }
            });

            //自定义表单校验规则
            /*form.verify({
                custom: function(value, item){ //value：表单的值、item：表单的DOM对象
                    value=$.trim(value);//去空格
                    $(item).val(value);
                    var customType=$(item).attr("customType");
                    if(value){//这里值存在则开始校验
                        switch(customType){
                            case "email":

                                return "类型不能为邮箱";
                                break;
                            case "idCard":
                                return "类型不能为身份证";
                                break;
                            case "phone":
                                return "类型不能为电话";
                                break;

                        }

                        console.log("有值"+value);
                    }
                    return "正在校验中";
                }
            });*/
            //提交form监听表单
            form.on('submit(update)',function(data){
                //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                $.ajax({
                    url:basePath+'/baseData/update',
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    success:function(data){
                        if(data.code==0){
                            //更新父元素的表格
                            window.parent.baseDataTree.reAsyncChildNodes(null, "refresh");
                            window.parent.query();
                        }
                        window.parent.closeEditPage();
                        window.parent.layer.msg(data.msg);
                    },
                    error:function(){

                    }
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</head>
<body>
<form class="layui-form layui-form-pane" action="" style="padding-top:10px;padding-left:20px;">
    <input type="hidden" name="id" value="${baseData.id!}">
    <input type="hidden" name="prePid" value="${baseData.prePid!}">
    <!--开始-->
    <!--节点名称-->
    <div class="layui-form-item">
        <label class="layui-form-label">节点名称</label>
        <div class="layui-input-block">
            <input name="name" value="${baseData.name!}" type="text" lay-verify="required"   autocomplete="off" placeholder="请输入节点名称" class="layui-input">
        </div>
    </div>
    <!--节点编码-->
    <div class="layui-form-item">
        <label class="layui-form-label">节点编码</label>
        <div class="layui-input-block">
            <input name="nodeCode" value="${baseData.nodeCode!}"  type="text" lay-verify="required"   autocomplete="off" placeholder="请输入节点编码" class="layui-input">
        </div>
    </div>
    <!--节点值-->
    <div class="layui-form-item">
        <label class="layui-form-label">节点值</label>
        <div class="layui-input-block">
            <input name="value" value="${baseData.value!}" type="text" autocomplete="off" placeholder="节点值" class="layui-input">
        </div>
    </div>
    <!--上级节点-->
    <div class="layui-form-item">
        <label class="layui-form-label">上级节点</label>
        <div class="layui-input-block">
            <select name="pid" xm-select="pid" xm-select-radio xm-select-search >
                <option value="">请选择上级</option>
            </select>
        </div>
    </div>
    <!--助记符-->
    <div class="layui-form-item">
        <label class="layui-form-label">助记符</label>
        <div class="layui-input-block">
            <input name="mnemonic" value="${baseData.mnemonic!}" type="text" autocomplete="off" placeholder="请输入助记符" class="layui-input">
        </div>
    </div>
    <!--状态-->
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <%
            if(baseData.status==1){
            %>
            <input type="radio" name="status" value="1" title="开启" checked>
            <input type="radio" name="status" value="2" title="禁用" >
            <%}
            else{
            %>
            <input type="radio" name="status" value="1" title="开启" >
            <input type="radio" name="status" value="2" title="禁用" checked>
            <%}%>
        </div>
    </div>
    <!--结束-->
    <div class="layui-form-item layui-hide">
        <button id="form-submit" class="layui-btn" lay-submit lay-filter="update">更新</button>
    </div>
</form>
</body>
</html>